/*
 * This file is part of the Try! Engine project.
 *
 * Copyright 2010-2011 Emanuele Bertoldi. All rights reserved.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * You should have received a copy of the modified BSD License along with this
 * program. If not, see <http://www.opensource.org/licenses/bsd-license.php>
 */

#include "exampleassetlibrary.h"
#include <lightemitter.h>
#include <animable.h>
#include <model3d.h>
#include <scenetransformable.h>
#include <graphicsmanager.h>

using namespace Try;

LightAsset::LightAsset()
    :   Asset("Light", "", "ExampleAssetLibrary", TRY_OBJECT_MIME)
{
}

void* LightAsset::create(Project* project)
{
    if (project)
    {
        String obj_name = project->findAvailableObjectName(this->name()).toStdString();

        Object* light = new Object(obj_name);

        LightEmitter* light_emitter = new LightEmitter(light, light->name());
        light_emitter->setPosition(Vector3(0, 25, 40));

        return light;
    }

    return 0;
}

EnvironmentAsset::EnvironmentAsset()
    :   Asset("Environment", "", "ExampleAssetLibrary", TRY_OBJECT_MIME)
{
}

void* EnvironmentAsset::create(Project* project)
{
    if (project)
    {
        String obj_name = project->findAvailableObjectName(this->name()).toStdString();

        Object* env = new Object(obj_name);

        Model3D* env_model = new Model3D(env, "models/platform/platform.scene.xml");

        return env;
    }

    return 0;
}

WalkingManAsset::WalkingManAsset()
    :   Asset("Walking Man", "", "ExampleAssetLibrary", TRY_OBJECT_MIME)
{
}

void* WalkingManAsset::create(Project* project)
{
    if (project)
    {
        String obj_name = project->findAvailableObjectName(this->name()).toStdString();

        Object* man = new Object(obj_name);

        Model3D* man_model = new Model3D(man, "models/man/man.scene.xml");
        man_model->addAnimation("animations/man.anim");
        man_model->runAnimation(0, 1, 0.01);

        return man;
    }

    return 0;
}

KnightAsset::KnightAsset()
    :   Asset("Knight", "", "ExampleAssetLibrary", TRY_OBJECT_MIME)
{
}

void* KnightAsset::create(Project* project)
{
    if (project)
    {
        String obj_name = project->findAvailableObjectName(this->name()).toStdString();

        Object* knight = new Object(obj_name);

        Model3D* knight_model = new Model3D(knight, "models/knight/knight.scene.xml");
        knight_model->addAnimation("animations/knight_order.anim");
        knight_model->addAnimation("animations/knight_attack.anim");

        return knight;
    }

    return 0;
}
